package fudan.se.lab2.controller;

import fudan.se.lab2.controller.request.ReviewRequest;
import fudan.se.lab2.domain.Mark;
import fudan.se.lab2.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
public class ReviewController {
    private final ReviewService reviewService;

    @Autowired
    public ReviewController(ReviewService reviewService) {
        this.reviewService = reviewService;
    }

    @PostMapping("/review")
    public ResponseEntity<Mark> review(@RequestBody ReviewRequest request) {
        return ResponseEntity.ok(reviewService.review(request));
    }

    @PostMapping("/download")
    public void download(@RequestBody String url, HttpServletResponse response) throws Exception {
        reviewService.download(url, response);
    }

    @PostMapping("/changeReview")
    public ResponseEntity<Boolean> changeReview(@RequestBody ReviewRequest request) {
        return ResponseEntity.ok(reviewService.changeReview(request));
    }

    @PostMapping("/refuseToChangeReview")
    public ResponseEntity<Boolean> refuseToChangeReview(@RequestBody ReviewRequest request) {
        return ResponseEntity.ok(reviewService.refuseToChangeReview(request));
    }
}
